package tedu.study.day06;

import java.util.Arrays;

public class Day06Practise {
    public static void main(String[] args) {
        int[] arr = getAarray(10,100);

        //MaxOfArray求数组元素最大值并放在最后一个元素的下一个位置
        //要求：声明整型数组并填充随机数据，找到最大值，将数组扩容并将最大值放末尾
        int max = arr[0];
        for(int i=1;i<arr.length;i++){
            if(arr[i]>max){
                max = arr[i];
            }
        }
        arr = Arrays.copyOf(arr,arr.length+1);
        arr[arr.length-1] = max;
        System.out.println(arr[arr.length-1]);
        System.out.println(arr[arr.length-2]);

        //数组排序的练习
        //要求：声明整型数组并填充数据，排序，输出排序后数据，倒序输出数据
        arr = getAarray(10,100);
        Arrays.sort(arr);
        System.out.println("排序后输出：");
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        System.out.println("倒序后输出：");
        for(int i=arr.length-1;i>=0;i--){
            System.out.println(arr[i]);
        }

        say();
        sayHi("zhangsan");
        sayHello("lisi",33);

        double a = getNum();
        int num = plus(5,6);
        int[] arr1 = getAarray(5,10);
    }

    public static void say(){
        System.out.println("大家好，我叫王五，今年39岁。");
    }

    public static void sayHi(String name){
        System.out.println("大家好，我叫"+name+"，今年39岁。");
    }

    public static void sayHello(String name,int age){
        System.out.println("大家好，我叫"+name+"，今年"+age+"岁。");
    }

    public static double getNum(){
        return 8.88888888;
    }

    public static int plus(int num1,int num2){
        int num = num1+num2;
        return num;
    }

    public static int[] getAarray(int len,int max){
        int[] arr = new int[len];
        for(int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*(max+1));
        }
        return arr;
    }
}
